﻿using com.guojin.core.io.message;
using com.guojin.mj.net.message.login;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RoomCard
{
    private static RoomCard instance;
    public static RoomCard GetInstance()
    {
        if (instance == null)
        {
            instance = new RoomCard();
        }
        return instance;
    }

    private int roomCardCounts;

    //监听房卡属性，发生改变同步至大厅
    public int RoomCardCounts
    {
        get { return roomCardCounts; }
        set
        {
            roomCardCounts = value;
            RoomCardPropertyChange();
        }
    }

    public void OnReceiveMsg713(string msg, Message data)
    {
        var roomCardRet = (RoomCardRet)data;
        SyncRoomCard(roomCardRet.roomCard);
    }

    public void SyncRoomCard(int counts)
    {
        RoomCardCounts = counts;
    }

    public void AddRoomCard(int counts)
    {
        RoomCardCounts += counts;
    }

    public void SubRoomCard(int counts)
    {
        RoomCardCounts -= counts;
    }

    private void RoomCardPropertyChange()
    {
        ChangeGameHallRoomCard();
    }

    private void ChangeGameHallRoomCard()
    {
        var temp = GameObject.Find("GameHallPage(Clone)");

        if (temp)
        {
            temp.GetComponent<GameHallPage>().RefreshRoomCardText();
        }
        else
        {
            Debug.Log("没有找到GameHall面板,无法重置房卡");
        }
    }
}
